%%
% Example.m
% This gives an example of how to use the codes here

%% Clear, add path to main codes, and load a simple dataset
clear
addpath(genpath('Codes'))
load Data/simple
numCells=size(spikes,2);
samplingRate=samprate;
%% Define Parameters
% Main Parameters

% filtering parameters for original signal
parameters.lowFilterFrequency=2;
parameters.highFilterFrequency=10;


% convolutional factor parameters
dictionaryTimeSpaninSeconds=.5; % how much before and after
parameters.dicionaryTimeSpan=round(dictionaryTimeSpaninSeconds*samplingRate);

% sampling rate
parameters.samplingRate=samprate;

% which frequencies to test
parameters.testingFrequencies=linspace(parameters.lowFilterFrequency,...
    parameters.highFilterFrequency,50);
parameters.testingFrequencyBandwidth=.5; % in hertz
% penalized likelihood
parameters.ridgeRegression=.1; % 0 will give maximum likelihood
% Cross-validation parameters
parameters.numberOfCrossValidationRuns=10; % 0 does not run CV results
%% Run Code
[waveformShape,RFE,RFEbyFreq,holdoutRFE,holdoutRFEbyFreq]=multiSpikeTrainToLFP(lfp,spikes,parameters);
%%
% [RFE,holdoutRFE]
figure(1);
plot(parameters.testingFrequencies,RFEbyFreq,parameters.testingFrequencies,holdoutRFEbyFreq)
legend('Training','Holdout')
xlabel('Frequencies, \it hz')
ylabel('RFE')
title('Prediction by Frequency, all neurons')



